package com.hex.ds.hdtp.core.web.script.test.controller;

import com.hex.bigdata.hbda.annotation.Log;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.script.test.dto.request.ScriptDataTestTaskRequestDto;
import com.hex.ds.hdtp.core.app.script.test.service.IScriptDataTestTaskService;
import com.hex.ds.hdtp.core.web.common.page.PageVo;
import com.hex.ds.hdtp.core.web.common.page.converter.IPageVoAndPageDtoConverter;
import com.hex.ds.hdtp.core.web.script.test.converter.IScriptDataTestTaskVoConverter;
import com.hex.ds.hdtp.core.web.script.test.vo.ScriptDataTestTaskVo;
import com.hex.ds.hdtp.core.web.script.test.vo.query.ScriptDataTestTaskQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.web.test.controller
 * @ClassName ScriptDataTestTaskController
 * @Description: 带数据测试任务-WEB接口
 * @Author: wz.li
 * @Date 2023/8/1 17:01
 * @Version v2.0.2
 **/
@Slf4j
@RestController
@Api(tags = "04-脚本测试：任务")
@RequestMapping("/api/script/test/task")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptDataTestTaskController {

    private final IScriptDataTestTaskService scriptDataTestTaskService;

    private final IScriptDataTestTaskVoConverter converter;

    private final IPageVoAndPageDtoConverter pageVoAndPageDtoConverter;

    /*
     * @Method: queryListByPage <br>
     * @Param: [scriptDataTestTaskQueryVo, pageVo] <br>
     * @Return: org.springframework.http.ResponseEntity <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 17:13 <br>
     * @Version： V2.0.2<br>
     */
    @GetMapping
    @ApiOperation("带数据测试任务-分页查询")
    public ResponseEntity queryListByPage(ScriptDataTestTaskQueryVo scriptDataTestTaskQueryVo, PageVo pageVo) {
        log.info("进入到【ScriptDataTestTaskController.queryListByPage】方法,参数：{}" + scriptDataTestTaskQueryVo.toString());
        final PageDto pageDto = pageVoAndPageDtoConverter.toPageDto(pageVo);
        ScriptDataTestTaskRequestDto requestDto = converter.toScriptDataTestTaskRequestDto(scriptDataTestTaskQueryVo);
        return ResponseEntity.ok(scriptDataTestTaskService.queryListByPage(requestDto, pageDto));
    }

    /*
     * @Method: add <br>
     * @Param: [scriptDataTestTaskVo] <br>
     * @Return: org.springframework.http.ResponseEntity <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 17:19 <br>
     * @Version： V2.0.2<br>
     */
    @Log("带数据测试任务-新增")
    @PostMapping
    @ApiOperation("带数据测试任务-新增")
    public ResponseEntity add(@RequestBody ScriptDataTestTaskVo scriptDataTestTaskVo) {
        log.info("进入到【ScriptDataTestTaskController.add】方法,参数：{}", scriptDataTestTaskVo.toString());
        return ResponseEntity.ok(scriptDataTestTaskService.createTestTask(converter.toScriptDataTestTaskRequestDto(scriptDataTestTaskVo)));
    }

    /*
     * @Method: update <br>
     * @Param: [scriptDataTestTaskVo] <br>
     * @Return: org.springframework.http.ResponseEntity <br>
     * @Description：更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 17:19 <br>
     * @Version： V2.0.2<br>
     */
    @Log("带数据测试任务-更新")
    @PutMapping
    @ApiOperation("带数据测试任务-更新")
    public ResponseEntity update(@RequestBody ScriptDataTestTaskVo scriptDataTestTaskVo) {
        log.info("进入到【ScriptDataTestTaskController.update】方法,参数：{}", scriptDataTestTaskVo.toString());
        scriptDataTestTaskService.modifyById(converter.toScriptDataTestTaskRequestDto(scriptDataTestTaskVo));
        return ResponseEntity.ok("更新成功");
    }

    /*
     * @Method: delete <br>
     * @Param: [pkIds] <br>
     * @Return: org.springframework.http.ResponseEntity <br>
     * @Description：批量删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 17:20 <br>
     * @Version： V2.0.2<br>
     */
    @Log("带数据测试任务-批量删除")
    @DeleteMapping(value = {"/{pkIds}"})
    @ApiOperation("带数据测试任务-批量删除")
    public ResponseEntity delete(@PathVariable("pkIds") @NotNull List<String> pkIds) {
        log.info("进入【ScriptDataTestTaskController.delete】方法,参数：" + pkIds);
        scriptDataTestTaskService.batchRemoveById(pkIds);
        return ResponseEntity.ok("删除成功");
    }

    /*
     * @Method: test <br>
     * @Param: [pkId] <br>
     * @Return: org.springframework.http.ResponseEntity <br>
     * @Description：带数据测试任务-测试<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/4 17:38 <br>
     * @Version： V2.0.2<br>
     */
    @Log("带数据测试任务-测试")
    @GetMapping(value = {"/test/{pkId}"})
    @ApiOperation("带数据测试任务-测试")
    public ResponseEntity test(@PathVariable("pkId") String pkId) {
        log.info("进入【ScriptDataTestTaskController.test】方法,参数：" + pkId);
        scriptDataTestTaskService.test(pkId);
        return ResponseEntity.ok("测试成功");
    }

    @Log("带数据测试任务-测试")
    @GetMapping(value = {"/data/alignment/{pkId}"})
    @ApiOperation("带数据测试任务-数据分析")
    public ResponseEntity dataAlignment(@PathVariable("pkId") String pkId) {
        log.info("进入【ScriptDataTestTaskController.dataAlignment】方法,参数：" + pkId);
        scriptDataTestTaskService.dataAlignment(pkId);
        return ResponseEntity.ok("数据分析成功");
    }
}
